<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table>
			<tr>
				<td colspan="4">计算器</td>
			</tr>
			<tr>
				<td colspan="4">
					请输入第一个数：<input type="text" id="num1">
				</td>
			</tr>
			<tr>
				<td colspan="4">
					请输入第二个数：<input type="text" id="num2"/>
				</td>
			</tr>
			<tr>
				<td>
					<input type="button" value="+" onclick="cal('+')"/>
				</td>
				<td>
					<input type="button" value="-" onclick="cal('-')"/>
				</td>
				<td>
					<input type="button" value="*" onclick="cal('*')"/>
				</td>
				<td>
					<input type="button" value="/" onclick="cal('/')"/>
				</td>
			</tr>
			<tr>
				<td colspan="4">
					所得结果为：<input type="text" id = "resultId"/>
				</td>
			</tr>
		</table>
		<script type="text/javascript">
			function cal (type){
				var inputObj1 = document.getElementById('num1');
				var inputObj2 = document.getElementById('num2');
				var result;
				switch(type){
					case '+':
					result = parseInt(inputObj1.value) + parseInt(inputObj2.value);
						break;
					case '-':
						result = parseInt(inputObj1.value) - parseInt(inputObj2.value);
						break;
					case '*':
						result = parseInt(inputObj1.value) * parseInt(inputObj2.value);
						break;
					case '/': 
						result = parseInt(inputObj1.value) / parseInt(inputObj2.value);
						break;
						
				}
				console.log(result);
				var resultObj = document.getElementById('resultId');
				resultObj.value = result;
				
			}</script>
	</body>
</html>
